home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.4 KB | 91 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- DOCPRINT.SX
-
- -- Other Files Required:
- -- NONE
-
- -- Purpose:
- -- Defines new subclasses of Document and Window and provides implementations
- -- of printDocument and printWindow to render them to a printer.
- in module docModule
-
- class MyDocumentClass (Document)
- end
-
- method printDocument self {class MyDocumentClass} -> (
- local p, scaleFactor, myTransform, oldTransform, \
- oldPosition, oldPresentedBy
-
- -- Create a Printer
- p := new PrinterSpace
- myTransform := mutableCopy identityMatrix
-
- oldPresentedBy := self.presentedBy
- prepend p self
-
- -- Start the document and see if we should continue
- if (printerDialog p) do (
- local firstPage, lastPage, i, n
-
- -- Record the firstPage and lastPage
- firstPage := p.firstPage
- p.firstPage := 1
- lastPage := p.lastPage
- p.lastPage := @all
-
- -- Clip the page range to the extent of the document
- if ((lastPage = @all) or (lastPage > self.size)) do
- lastPage := self.size
-
- -- Record the old state of the Document, so that we can reset it
- oldPosition := self.cursor
- oldTransform := self.transform
-
- for i := firstPage to lastPage do (
- -- If this page is in the correct page range
- -- Go to that page and find out how best to
- -- scale it. Since different pages can have
- -- different boundaries, we have to do it everytime.
- goto self i
- scaleFactor := min (p.boundary.width / \
- self.boundary.width) \
- (p.boundary.height / \
- self.boundary.height)
-
- -- Set the transform based on the scaling factor
- reset myTransform
- scale myTransform scaleFactor scaleFactor
- self.transform := myTransform
-
- -- Take a snapshot of the page
- printFrame p
-
- -- Move on to the next page
- flushPage p
- )
-
- -- Flush the document
- flushDocument p
-
- -- Reset the state of the document
- goto self oldPosition
- self.transform := oldTransform
- )
-
- prepend oldPresentedBy self
- )
-
- class MyWindowClass (Window)
- end
-
- method printWindow self {class MyWindowClass} -> (
- local doc := self[1]
- self.compositor.enabled := false
-
- printDocument doc
-
- self.compositor.enabled := true
- )
- -->>>
-